<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-05 12:05:33
 * @LastEditTime: 2023-08-15 14:45:10
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Http\Services\Storage;

use App\Http\Services\Service;
use App\Repositories\ProPotRawSendDetailRepository;
use App\Repositories\ProPotRawSendRepository;

use Illuminate\Support\Facades\DB;

/**
 * @property ProPotRawSendDetailRepository $detail
 */
class ProRawService extends Service
    {

    public function __construct(ProPotRawSendRepository $Repository, ProPotRawSendDetailRepository $detail)
        {
        $this->repository = $Repository;
        $this->detail     = $detail;
        }
    public function list()
        {
        $data = $this->repository->condition(request())->getGrid();
        return $data;
        }
    public function details()
        {
        $data = $this->detail->condition(request())->getGrid();
        return $data;
        }
    protected function delete()
        {
        return $this->repository->whereIn("id", $this->getRequestIds())->get()->filter(function ($raw)
            {
            if ($raw->status_id != "0") {
                fail("删除失败！已出库状态禁止删除！");
                }
            });
        }

    protected function audit()
        {
        return $this->repository->whereIn("id", $this->getRequestIds())->get()->filter(function ($raw)
            {
            if ($raw->status_id != "0") {
                fail("出库失败！已出库状态禁止出库！");
                }
            $this->repository->outStorage($raw);
            });
        }
    protected function noaudit()
        {
        return $this->repository->whereIn("id", $this->getRequestIds())->get()->filter(function ($raw)
            {
            if ($raw->status_id != "1") {
                fail("取消出库失败！已出库状态禁止取消出库！");
                }
            $this->repository->nooutStorage($raw);
            });
        }
    }